package ar.republicagroup.gestion.util.exportar;

import ar.republicagroup.gestion.util.exportar.beans.LiquidacionBean;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
import org.apache.log4j.Logger;

public class Exportar {
    
    private static Logger log = Logger.getLogger(Exportar.class);
    
    public static void toPDF(InputStream file, List<LiquidacionBean> datos, Map param,String title) throws Exception {
           
            log.info("Generando reportePDF...");
                     
            JRBeanCollectionDataSource data;
            data = new JRBeanCollectionDataSource(datos);
                                
            //Usando el archivo JASPER (compilado)
            JasperReport rep = (JasperReport) JRLoader.loadObject(file);
            JasperPrint print = JasperFillManager.fillReport(rep, param, data);
                       
            //Creando y Visualizando PDF
            JasperViewer viewer = new JasperViewer(print, false);
            viewer.setTitle(title);
            viewer.setVisible(true);
            
            log.info("Reporte generado!");
            
    }
    
    
    
}
